package com.xxx.server.controller;


import com.xxx.server.pojo.Employee;
import com.xxx.server.pojo.EmployeeEc;
import com.xxx.server.service.EmployeeEcService;
import com.xxx.server.utils.RespBean;
import com.xxx.server.utils.RespPageBean;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import javax.annotation.Resource;
import java.time.LocalDate;

/**
 * <p>
 * 员工奖罚表 前端控制器
 * </p>
 *
 * @author HeYan
 * @since 2024-05-01
 */
@RestController
@RequestMapping("/employee-ec")
public class EmployeeEcController {
    @Resource
    private EmployeeEcService employeeEcService;


    @PostMapping("/")
    public RespBean addEmployeeEcConftroller(@RequestBody EmployeeEc employee) {
        if (employeeEcService.save(employee)) {
            return RespBean.success("添加成功");
        } else {
            return RespBean.error("添加失败");
        }
    }

    @ApiOperation(value = "获取所有员工惩罚（分页）")
    @GetMapping("/")
    public RespPageBean getEmployee(@RequestParam(defaultValue = "1") Integer currentPage,
                                    @RequestParam(defaultValue = "10") Integer size){
        return employeeEcService.getEmployeeEcByPage(currentPage,size);
    }

    @ApiOperation(value = "更新员工")
    @PutMapping("/")
    public RespBean updateEmp(@RequestBody EmployeeEc employee) {
        if (employeeEcService.updateById(employee)) {
            return RespBean.success("更新成功！");
        }
        return RespBean.error("更新失败！");
    }

    @ApiOperation(value = "删除员工")
    @DeleteMapping("/{id}")
    public RespBean deleteEmp(@PathVariable Integer id) {
        if (employeeEcService.removeById(id)) {
            return RespBean.success("删除成功！");
        }
        return RespBean.error("删除失败！");
    }

    @ApiOperation(value = "获取所有员工（分页）")
    @GetMapping("/search")
    public RespPageBean getEmployee(@RequestParam(defaultValue = "1") Integer currentPage,
                                    @RequestParam(defaultValue = "10") Integer size,
                                    EmployeeEc employee) {
        return employeeEcService.getEmployeeByPage(currentPage, size, employee);
    }
}

